<?php

namespace App\Livewire;

use App\Enums\BorrowStatus;
use App\Models\Category;
use Filament\Notifications\Notification;
use Kalnoy\Nestedset\Collection;
use Livewire\Attributes\On;
use Livewire\Component;

class NavList extends Component
{
    public  array $categories ;
    public ?Category $category = null;

    public int $borrowCount = 0;
    public function mount($category)
    {
        $this->categories = Category::all()->toTree()->toArray();
        $this->getBorrowCount();
    }

    #[On('borrowBook')]
    public function getBorrowCount()
    {
        if (auth('frontend')->check()){
            $this->borrowCount = auth('frontend')->user()
                ->borrowRecord()
                ->where('returned',BorrowStatus::STATUS_BORROWING)
                ->count();
        }
    }


    #[On('success')]
    public function successNotice(string $message): Notification
    {
        return Notification::make()
            ->title($message)
            ->success()
            ->send();
    }
    #[On('error')]
    public function errorNotice(string $message): Notification
    {
        return Notification::make()
            ->title($message)
            ->danger()
            ->send();
    }
}
